

package legstar.trans.choice;
import java.util.Hashtable;

import com.legstar.coxb.CobolElementVisitor;
import com.legstar.coxb.ICobolBinding;
import com.legstar.coxb.ICobolChoiceBinding;
import com.legstar.coxb.ICobolUnmarshalChoiceStrategy;
import com.legstar.coxb.host.HostException;

import legstar.trans.afsbasft.BasfRecord;

/** 
 * Skeleton implementation of a custom choice selection strategy. Modify this
 * code to select a suitable alternative.
 */
public class DetailStrategy implements ICobolUnmarshalChoiceStrategy {

    /** {@inheritDoc} */
    public ICobolBinding choose(
        final ICobolChoiceBinding choice,
        final Hashtable < String, Object > variablesMap,
        final CobolElementVisitor visitor) throws HostException {
        
        /* Get the parent value object which properties might help select the
         * right alternative. */
        BasfRecord valueObject = (BasfRecord) choice.getParentValueObject();
        assert (valueObject != null);
        
        /* Replace following code with actual logic. */
         
        int index = valueObject.getBasfKey().getBasfRecordType();
        switch (index) {
        case 0:
            return choice.getAlternativeByName("BasfDetail");
        case 1:
            return choice.getAlternativeByName("BasrfDetail");
        case 2:
            return choice.getAlternativeByName("BasnfDetail");
        case 3:
            return choice.getAlternativeByName("BascfDetail");
        case 4:
            return choice.getAlternativeByName("BasafDetail");
        case 5:
            return choice.getAlternativeByName("BasgfDetail");
        case 6:
            return choice.getAlternativeByName("BasglfDetail");
        case -1:
            /* An exemple of how to signal an exception.*/
            throw (new HostException("Unable to select an alternative"));
        default:
            /* Null will let the default choice strategy apply. */
            return null;
        }
    }
}


